import { EggAppConfig, EggAppInfo, PowerPartial } from "egg";

export default (appInfo: EggAppInfo) => {
  const config = {} as PowerPartial<EggAppConfig>;

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + "_1538113168764_527";
  config.saltRounds = 10;
  config.security = {
    domainWhiteList: ["localhost:4444", "localhost:7001", "210.12.224.197:8080", "localhost:3000"],
    // FIXME: for test
    csrf: {
      enable: false
    }
  };
  config.sequelize = {
    dialectOptions: {
      requestTimeout: 60000
    },
    define: {
      timestamps: true,
      updatedAt: "modify_time",
      createdAt: "create_time",
      freezeTableName: true
    }
  };
  config.cors = {
    credentials: true,
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS',
  };
  config.torlerateLoginFailTimes = 5;
  config.captchaTimeout = 60000;
  config.bodyParser = {
    jsonLimit: "1024mb",
    formLimit: "1024mb"
  };
  // add your egg config in here
  config.middleware = [];

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`
  };

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig
  };
};
